<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {

	public function login()
	{
		if($this->session->userdata('logged_in'))
		{
			redirect(site_url('mainpage'),'refresh');
		}
		$this->load->helper('form');
		$data['error'] = "";
		$this->load->view('login.php',$data);
	}
	
	public function log()
	{
		if($this->session->userdata('logged_in'))
		{
			redirect(site_url('mainpage'),'refresh');
		}
		
		$username = "test";
		$password = "test";
		
		//$query = $this->db->get_where('employee', array('id' => $id), $limit, $offset);
		
		if($username==$_POST['username']&&$password==$_POST['password'])
		{
			$newdata = array(
                   'logged_in' => TRUE
               );

			$this->session->set_userdata($newdata);
			
			redirect(site_url('mainpage'),'refresh');
		}
		else {
			$this->load->helper('form');
			$data['error'] = "Username or Password is wrong.";
			$this->load->view('login.php',$data);
		}
	}
	
	public function logout()
	{
		if($this->session->userdata('logged_in'))
		{
			$newdata = array(
                   'logged_in' => FALSE
               );

			$this->session->set_userdata($newdata);
		}
		redirect(site_url('login'),'refresh');
	}
}

